# -*- coding: utf-8 -*-
from export.distributors.ugcontract import Ugcontract


class ExportCatalog():
    products = []

    def __init__(self, csv, type, delimetr=';'):
        self.csv = csv
        self.delimetr = delimetr
        self.convertCSVtoListProduct()

    def convertCSVtoListProduct(self):
        csvContent = self.csv.split('\n')
        csvContent = csvContent[1:]
        ugcontract = Ugcontract()
        for csvRow in csvContent:
            if csvRow!=u'':
                csvCell = csvRow.decode('utf8').replace('"','').split(self.delimetr)
                if csvCell!=u'':
                    product = ugcontract.searchBySitePage(csvCell[0], csvCell[2])
                    if product:
                        if csvCell[1]:
                            product.entity_id=csvCell[1]
                            product.save()
                        self.products.append(product)
